#include <iostream>

using namespace std;
//指针与函数:利用指针作函数参数，可以修改实参的值

//实现两个数字进行交换
//1、值传递
void swap1(int a, int b) {
    int temp = a;
    a = b;
    b = temp;
}

//2、址传递
void swap2(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int main() {
    int a = 10;
    int b = 20;
    //1、值传递
    swap1(a, b);//值传递不会改变实参
    cout << "a=" << a << ",b=" << b << endl;
    cout << "---------" << endl;
    //2、址传递
    swap2(&a, &b);//地址传递会改变实参
    cout << "a=" << a << ",b=" << b << endl;
    return 0;
}

